{#

This file is part of the Sonata package.

(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}
{% set _preview      = block('preview') %}
{% set _form         = block('form') %}
{% set _show         = block('show') %}
{% set _list_table   = block('list_table') %}
{% set _list_filters = block('list_filters') %}
{% set _tab_menu     = block('tab_menu') %}
{% set _content      = block('content') %}
{% set _title        = block('title') %}
{% set _breadcrumb   = block('breadcrumb') %}
{% set _actions      = block('actions') %}
{% set _navbar_title = block('navbar_title') %}
<!DOCTYPE html>
<html {% block html_attributes %}class="no-js"{% endblock %}>
    <head>
        {% block meta_tags %}
            <meta charset="UTF-8">
            <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
        {% endblock %}

        {% block stylesheets %}

            {% for stylesheet in admin_pool.getOption('stylesheets', []) %}
                <link rel="stylesheet" href="{{ asset(stylesheet) }}">
            {% endfor %}

        {% endblock %}

        {% block javascripts %}
            <script>
                window.SONATA_CONFIG = {
                    CONFIRM_EXIT: {% if admin_pool is defined and admin_pool.getOption('confirm_exit') %}true{% else %}false{% endif %},
                    USE_SELECT2: {% if admin_pool is defined and admin_pool.getOption('use_select2') %}true{% else %}false{% endif %},
                    USE_ICHECK: {% if admin_pool is defined and admin_pool.getOption('use_icheck') %}true{% else %}false{% endif %}
                };
                window.SONATA_TRANSLATIONS = {
                    CONFIRM_EXIT:  '{{ 'confirm_exit'|trans({}, 'SonataAdminBundle')|escape('js') }}'
               };
            </script>

            {% for javascript in admin_pool.getOption('javascripts', []) %}
                <script src="{{ asset(javascript) }}"></script>
            {% endfor %}

            {# localize select2 #}
            {% if admin_pool is defined and admin_pool.getOption('use_select2') %}
                {% set locale = app.request.locale %}
                {% if locale == 'pt' %}{% set locale = 'pt_PT' %}{% endif %}

                {# omit default EN locale #}
                {% if locale[:2] != 'en' %}
                    <script src="{{ asset('bundles/sonataadmin/vendor/select2/select2_locale_' ~ locale|replace({'_':'-'}) ~ '.js') }}"></script>
                {% endif %}
            {% endif %}

        {% endblock %}

        <title>
        {% block sonata_head_title %}
            {{ 'Admin'|trans({}, 'SonataAdminBundle') }}

            {% if _title is not empty %}
                {{ _title|raw }}
            {% else %}
                {% if action is defined %}
                    -
                    {% for menu in admin.breadcrumbs(action) %}
                        {% if not loop.first %}
                            {%  if loop.index != 2 %}
                                &gt;
                            {% endif %}

                            {{ menu.label }}
                        {% endif %}
                    {% endfor %}
                {% endif %}
            {% endif%}
        {% endblock %}
        </title>
    </head>
    <body {% block body_attributes %}class="sonata-bc skin-black fixed"{% endblock %}>
        {% block sonata_header %}
            <header class="header">
                {% block sonata_header_noscript_warning %}
                    <noscript>
                        <div class="noscript-warning">
                            {{ 'noscript_warning'|trans({}, 'SonataAdminBundle') }}
                        </div>
                    </noscript>
                {% endblock %}
                {% block logo %}
                    {% spaceless %}
                    <a class="logo" href="{{ url('sonata_admin_dashboard') }}">
                        {% if 'single_image' == admin_pool.getOption('title_mode') or 'both' == admin_pool.getOption('title_mode') %}
                            <img src="{{ asset(admin_pool.titlelogo) }}" alt="{{ admin_pool.title }}">
                        {% endif %}
                        {% if 'single_text' == admin_pool.getOption('title_mode') or 'both' == admin_pool.getOption('title_mode') %}
                            <span>{{ admin_pool.title }}</span>
                        {% endif %}
                    </a>
                    {% endspaceless %}
                {% endblock %}
                {% block sonata_nav %}
                    {% if admin_pool is defined %}
                        <nav class="navbar navbar-static-top" role="navigation">
                            <a href="#" class="navbar-btn sidebar-toggle" data-toggle="offcanvas" role="button">
                                <span class="sr-only">Toggle navigation</span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                            </a>

                            <div class="navbar-left">
                                {% block sonata_breadcrumb %}
                                    {% if _breadcrumb is not empty or action is defined %}
                                        <ol class="nav navbar-top-links breadcrumb">
                                            {% if _breadcrumb is empty %}
                                                {% if action is defined %}
                                                    {% for menu in admin.breadcrumbs(action) %}
                                                        {% if not loop.last  %}
                                                            <li>
                                                                {% if menu.uri is not empty %}
                                                                    <a href="{{ menu.uri }}">{{ menu.label|raw }}</a>
                                                                {% else %}
                                                                    {{ menu.label }}
                                                                {% endif %}
                                                            </li>
                                                        {% else %}
                                                            <li class="active"><span>{{ menu.label }}</span></li>
                                                        {% endif %}
                                                    {% endfor %}
                                                {% endif %}
                                            {% else %}
                                                {{ _breadcrumb|raw }}
                                            {% endif %}
                                        </ol>
                                    {% endif %}
                                {% endblock sonata_breadcrumb %}
                            </div>

                            {% block sonata_top_nav_menu %}
                                <div class="navbar-right">
                                    <ul class="nav navbar-nav">
                                        <li class="dropdown">
                                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                                                <i class="fa fa-plus-square fa-fw"></i> <i class="fa fa-caret-down"></i>
                                            </a>
                                            {% include admin_pool.getTemplate('add_block') %}
                                        </li>
                                        <li class="dropdown user-menu">
                                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                                                <i class="fa fa-user fa-fw"></i> <i class="fa fa-caret-down"></i>
                                            </a>
                                            <ul class="dropdown-menu dropdown-user">
                                                {% include admin_pool.getTemplate('user_block') %}
                                            </ul>
                                        </li>
                                    </ul>
                                </div>
                            {% endblock %}
                        </nav>
                    {% endif %}
                {% endblock sonata_nav %}
            </header>
        {% endblock sonata_header %}

        {% block sonata_wrapper %}
            <div class="wrapper row-offcanvas row-offcanvas-left">
                {% block sonata_left_side %}
                    <aside class="left-side sidebar-offcanvas">
                        <section class="sidebar">
                            {% block sonata_side_nav %}
                                {% block sonata_sidebar_search %}
                                    {% if app.security.token and is_granted('ROLE_SONATA_ADMIN') %}
                                        <form action="{{ url('sonata_admin_search') }}" method="GET" class="sidebar-form" role="search">
                                            <div class="input-group custom-search-form">
                                                <input type="text" name="q" value="{{ app.request.get('q') }}" class="form-control" placeholder="{{ 'search_placeholder'|trans({}, 'SonataAdminBundle') }}">
                                                    <span class="input-group-btn">
                                                        <button class="btn btn-flat" type="submit">
                                                            <i class="fa fa-search"></i>
                                                        </button>
                                                    </span>
                                            </div>
                                        </form>
                                    {% endif %}
                                {% endblock sonata_sidebar_search %}

                                {% block side_bar_before_nav %} {% endblock %}
                                {% block side_bar_nav %}
                                    {% if app.security.token and is_granted('ROLE_SONATA_ADMIN') %}
                                        <ul class="sidebar-menu">
                                            {% for group in admin_pool.dashboardgroups %}
                                                {% set display = (group.roles is empty or is_granted('ROLE_SUPER_ADMIN') ) %}
                                                {% for role in group.roles if not display %}
                                                    {% set display = is_granted(role) %}
                                                {% endfor %}

                                                {# Do not display the group label if no item in group is available #}
                                                {% set item_count = 0 %}
                                                {% if display %}
                                                    {% for admin in group.items if item_count == 0 %}
                                                        {% if admin.hasroute('list') and admin.isGranted('LIST') %}
                                                            {% set item_count = item_count+1 %}
                                                        {% endif %}
                                                    {% endfor %}
                                                {% endif %}

                                                {% if display and (item_count > 0) %}
                                                    {% set active = false %}
                                                    {% for admin in group.items %}
                                                        {% if admin.hasroute('list') and admin.isGranted('LIST') and app.request.get('_sonata_admin') == admin.code %}
                                                            {% set active = true %}
                                                        {% endif %}
                                                    {% endfor %}
                                                    <li class="treeview{% if active %} active{% endif %}">
                                                        <a href="#">
                                                            {% if group.icon|default() %}{{ group.icon|raw }}{% endif %}
                                                            <span>{{ group.label|trans({}, group.label_catalogue) }}</span>
                                                            <i class="fa pull-right fa-angle-left"></i>
                                                        </a>
                                                        <ul class="treeview-menu{% if active %} active{% endif %}">
                                                            {% for admin in group.items %}
                                                                {% if admin.hasroute('list') and admin.isGranted('LIST') %}
                                                                    <li{% if app.request.get('_sonata_admin') == admin.code %} class="active"{% endif %}><a href="{{ admin.generateUrl('list')}}"><i class="fa fa-angle-double-right"></i> {{ admin.label|trans({}, admin.translationdomain) }}</a></li>
                                                                {% endif %}
                                                            {% endfor %}
                                                        </ul>
                                                    </li>
                                                {% endif %}
                                            {% endfor %}
                                        </ul>
                                    {% endif %}
                                {% endblock side_bar_nav %}
                                {% block side_bar_after_nav %}
                                    <p class="text-center small" style="border-top: 1px solid #444444; padding-top: 10px"><a href="http://sonata-project.org" rel="noreferrer" target="_blank">sonata project</a></p>
                                {% endblock %}
                            {% endblock sonata_side_nav %}
                        </section>
                    </aside>
                {% endblock sonata_left_side %}

                <aside class="right-side">
                    {% block sonata_page_content %}
                        <section class="content-header">
                            {% block sonata_page_content_header %}
                                {% block sonata_page_content_nav %}
                                    {% if _tab_menu is not empty or _actions is not empty %}
                                        <nav class="navbar navbar-default" role="navigation">
                                            {% block tab_menu_navbar_header %}
                                                {% if _navbar_title is not empty %}
                                                    <div class="navbar-header">
                                                        <span class="navbar-brand">{{ _navbar_title|raw }}</span>
                                                    </div>
                                                {% endif %}
                                            {% endblock %}
                                            <div class="container-fluid">
                                                <div class="navbar-left">
                                                    {% if _tab_menu is not empty %}
                                                        {{ _tab_menu|raw }}
                                                    {% endif %}
                                                </div>

                                                {% if _actions|replace({ '<li>': '', '</li>': '' })|trim is not empty %}
                                                    <ul class="nav navbar-nav navbar-right">
                                                        <li class="dropdown sonata-actions">
                                                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">{{ 'link_actions'|trans({}, 'SonataAdminBundle') }} <b class="caret"></b></a>
                                                            <ul class="dropdown-menu" role="menu">
                                                                {{ _actions|raw }}
                                                            </ul>
                                                        </li>
                                                    </ul>
                                                {% endif %}
                                            </div>
                                        </nav>
                                    {% endif %}
                                {% endblock sonata_page_content_nav %}

                            {% endblock sonata_page_content_header %}
                        </section>

                        <section class="content">
                            {% block sonata_admin_content %}

                                {% block notice %}
                                    {% include 'SonataCoreBundle:FlashMessage:render.html.twig' %}
                                {% endblock notice %}

                                {% if _preview is not empty %}
                                    <div class="sonata-ba-preview">{{ _preview|raw }}</div>
                                {% endif %}

                                {% if _content is not empty %}
                                    <div class="sonata-ba-content">{{ _content|raw }}</div>
                                {% endif %}

                                {% if _show is not empty %}
                                    <div class="sonata-ba-show">{{ _show|raw }}</div>
                                {% endif %}

                                {% if _form is not empty %}
                                    <div class="sonata-ba-form">{{ _form|raw }}</div>
                                {% endif %}

                                {% if _list_table is not empty or _list_filters is not empty %}
                                    <div class="row">
                                        <div class="sonata-ba-list {% if _list_filters|trim %}col-md-10{% else %}col-md-12{% endif %}">
                                            {{ _list_table|raw }}
                                        </div>

                                        {% if _list_filters|trim %}
                                            <div class="sonata-ba-filter col-md-2">
                                                {{ _list_filters|raw }}
                                            </div>
                                        {% endif %}
                                    </div>
                                {% endif %}
                            {% endblock sonata_admin_content %}
                        </section>
                    {% endblock sonata_page_content %}
                </aside>

            </div>
        {% endblock sonata_wrapper %}
    </body>
</html>
